package com.my.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.my.annotation.SystemOperatorLog;
import com.my.constant.ErrorCode;
import com.my.entity.Log;
import com.my.entity.ResponseData;
import com.my.service.LogService;

@Controller
@RequestMapping(value="/log")
public class LogAction {
	private static final Logger logger = LoggerFactory.getLogger(LogAction.class);
	@Resource
	private LogService logService;

	
	@RequestMapping(value = "/log_manager")
	public String gotoLogManager(HttpServletRequest request) {
		return "log/log_manager";
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@RequestMapping("delete_log")
	@SystemOperatorLog(description="删除日志信息")
	public @ResponseBody ResponseData<Integer> deleteLog(Long id) {
		try {
			Assert.notNull(id);
			logService.deleteByPrimaryKey(id);
			return new ResponseData<Integer>(ErrorCode.SUCCESS,
					ErrorCode.SUCCESS.getDesc(), null, false,null);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResponseData<Integer>(ErrorCode.FAUILURE,
					ErrorCode.FAUILURE.getDesc(), null, true,null);
		}

	}

	/**
	 * 查看错误日志
	 * @return
	 */
	@RequestMapping("log_error_list")
	public String selectAllErrorLop(HttpServletRequest request) {
		List<Log> logErrorList = logService.selectAllErrorLop();
		request.setAttribute("logErrorList", logErrorList);
		return "log/log_error_list";
	}
	
	/**
	 * 查看正确日志
	 * @return
	 */
	@RequestMapping("log_right_list")
	public String selectAllRightLog(HttpServletRequest request) {
		List<Log> logRightList = logService.selectAllRightLog();
		request.setAttribute("logRightList", logRightList);
		return "log/log_right_list";
	}

	
}
